﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace childcare
{
    public partial class frmtien_nam : Form
    {
        SqlConnection con = new SqlConnection();
        private DataTable dt = new DataTable();
        private SqlDataAdapter da = new SqlDataAdapter();
        public frmtien_nam()
        {
            InitializeComponent();
        }

        private void frmtien_nam_Load(object sender, EventArgs e)
        {
            string connect = @"Data Source=BLACK-PC\SQLEXPRESS;Initial Catalog=Childcare;Integrated Security=True";
            con = new SqlConnection(connect);
            connectdatabase.Openconnect();
            dgvtiennam.DataSource = connectdatabase.ex("select DATEPART(YEAR,thang) [Năm], SUM(tong_tien) [Tổng] from hoc_phi group by DATEPART(YEAR,thang)");
            // databinding();
        }

        private void btntktiennam_Click(object sender, EventArgs e)
        {
            dt.Clear();
            SqlCommand commandsearch = new SqlCommand();
            commandsearch.Connection = con;
            commandsearch.CommandType = CommandType.Text;
            commandsearch.CommandText = "select DATEPART(YEAR,thang) [Năm], SUM(tong_tien) [Tổng]"
            + "from hoc_phi where DATEPART(YEAR,thang) = @nam group by DATEPART(YEAR,thang)";
            SqlParameter pram = commandsearch.Parameters.Add("@nam", SqlDbType.VarChar);
            pram.Value = txttktien_nam.Text;
            da.SelectCommand = commandsearch;
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                dgvtiennam.DataSource = dt;
            }
            else
            {
                dgvtiennam.DataSource = dt;
                MessageBox.Show("Không tìm thấy năm này!", "THÔNG BÁO", MessageBoxButtons.OK);
            }
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
            frmadmin _frmnew = new frmadmin();
            _frmnew.Show();
        }
    }
}
